/*
 * Copyright (C) 2019-2020 Alibaba Group Holding Limited
 */
#ifndef _YOC_MEDIAPLAYER_H_
#define _YOC_MEDIAPLAYER_H_

#include <media.h>

typedef enum { SOURCE_CLOUD, SOURCE_LOCAL, SOURCE_BT, NUM_SOURCES } mplayer_source_t;

typedef enum {
    MPLAYER_STATE_PLAYING,
    MPLAYER_STATE_PAUSE,
    MPLAYER_STATE_ZERO_VOLUME,
    MPLAYER_STATE_MUTE,
    NUM_STATES
} mplayer_state_t;

/**
 * @brief  init media player
 * @param  [in] stack_size     : stack size of media task
 * @param  [in] media_evt      : callback function to handle media event
 * @param  [in] min_vol        : minimum volume, if current system vol is 0, TTS will be set to min_vol
 * @return 0 on success, negative value on failed
 */
int8_t mplayer_init(size_t stack_size, media_evt_t media_evt, uint8_t min_vol);

/**
 * @brief  increase volume
 * @param  [in] source          : indicate where the action comes from
 * @param  [in] vol             : volume step
 * @return 0 on success, negative value on failed
 */
int8_t mplayer_vol_up(mplayer_source_t source, int16_t vol);

/**
 * @brief  decrease volume
 * @param  [in] source          : indicate where the action comes from
 * @param  [in] vol             : volume step
 * @return 0 on success, negative value on failed
 */
int8_t mplayer_vol_down(mplayer_source_t source, int16_t vol);

/**
 * @brief  set volume
 * @param  [in] source          : indicate where the action comes from
 * @param  [in] vol             : target volume
 * @return 0 on success, negative value on failed
 */
int8_t mplayer_vol_set(mplayer_source_t source, int16_t vol);

/**
 * @brief  get current volume
 * @return current volume, should be in 0~100
 */
int8_t mplayer_vol_get(void);

/**
 * @brief  pause music playback
 * @param  [in] source          : indicate where the action comes from
 * @return 0 on success, negative value on failed
 */
int8_t mplayer_pause(mplayer_source_t source);

/**
 * @brief  resume music playback
 * @param  [in] source          : indicate where the action comes from
 * @return 0 on success, negative value on failed
 */
int8_t mplayer_resume(mplayer_source_t source);

/**
 * @brief  start playing new stream
 * @param  [in] source          : indicate where the action comes from
 * @param  [in] type            : can be system or music
 * @param  [in] url             : stream url
 * @param  [in] seek_time       : 0 - play from beginning
 *                                >0 - play from seek position
 * @param  [in] resume          : resume music automatically
 * @return 0 on success, negative value on failed
 */
int8_t mplayer_start(mplayer_source_t source, int type, char *url, uint64_t seek_time,
                     uint8_t resume);

/**
 * @brief  stop playing current stream
 * @param  [in] source          : indicate where the action comes from
 * @param  [in] type            : can be system or music
 * @return 0 on success, negative value on failed
 */
int8_t mplayer_stop(mplayer_source_t source, int type);

/**
 * @brief  set media player to lpm mode
 * @param  [in] state          : 0 - enter lpm, 1 - leave lpm
 * @return 0 on success, negative value on failed
 */
int8_t mplayer_lpm(uint8_t state);

/**
 * @brief  get current media player state
 * @return media player state
 */
mplayer_state_t mplayer_get_state(void);

/**
 * @brief  deinit media player
 * @return 0 on success, negative value on failed
 */
int8_t mplayer_deinit(void);

#endif //_YOC_MEDIAPLAYER_H_